﻿using System;
using System.Collections.Generic;
using ICSharpCode.Decompiler.ILAst;
using Mono.Cecil;

namespace CSLua
{
	// Token: 0x02000013 RID: 19
	public class LuaExpressionBuilder : ExpressionBuilder
	{
		// Token: 0x17000017 RID: 23
		// (get) Token: 0x06000098 RID: 152 RVA: 0x00004BD1 File Offset: 0x00002DD1
		protected override Dictionary<string, string> operateMapping_1
		{
			get
			{
				return this._operateMapping_1;
			}
		}

		// Token: 0x17000018 RID: 24
		// (get) Token: 0x06000099 RID: 153 RVA: 0x00004BD9 File Offset: 0x00002DD9
		protected override Dictionary<string, string> operateMapping_2
		{
			get
			{
				return this._operateMapping_2;
			}
		}

		// Token: 0x0600009A RID: 154 RVA: 0x00004BE4 File Offset: 0x00002DE4
		public LuaExpressionBuilder(MethodBodyPhase methodBuilder, ILExpression expressionContext) : base(methodBuilder, expressionContext)
		{
		}

		// Token: 0x0600009B RID: 155 RVA: 0x000049CF File Offset: 0x00002BCF
		protected override bool isForceUnvirtual(MethodReference methodRef)
		{
			return this.buildContext.isForceUnvirtual(methodRef);
		}

		// Token: 0x0600009C RID: 156 RVA: 0x000049DD File Offset: 0x00002BDD
		protected override bool isForceVirtualCall()
		{
			return false;
		}

		// Token: 0x0600009D RID: 157 RVA: 0x00004CD0 File Offset: 0x00002ED0
		public override string getUnvirtualMethodId(MethodReference refe)
		{
			/*if (!this.buildContext.isLuaType(refe.DeclaringType))
			{
				string id;
				if (!this.buildContext.refmethods.TryGetValue(refe, out id))
				{
					id = this.buildContext.getTypeId(refe.DeclaringType, false) + "_" + this.buildContext.getMethodName(refe);
					id = this.buildContext.toSimpleName("F_", id);
					this.buildContext.refmethods.Add(refe, id);
				}
				return id;
			}*/
			string methodName = this.buildContext.getMethodName(refe);
			if (refe.DeclaringType.isEquals(this.mainTypeDef))
			{
				this.buildContext.addSelfMethodCache(methodName);
				return methodName;
			}
			return this.buildContext.getTypeId(refe.DeclaringType, false) + "." + methodName;
		}

		// Token: 0x0600009E RID: 158 RVA: 0x00004DA0 File Offset: 0x00002FA0
		public override void buildUnvirtualCall(CodeWriter writer, ILExpression expression, MethodDefinition methodDef, List<string> typeArgs)
		{
			writer.code(this.getUnvirtualMethodId(methodDef) + "(");
			if (typeArgs.Count > 0)
			{
				writer.dot<string>(typeArgs, delegate(string targ, int idx)
				{
					writer.code(targ);
				});
				if (expression.Arguments.Count > 0)
				{
					writer.code(",");
				}
			}
			writer.dot<ILExpression>(expression.Arguments, delegate(ILExpression exp, int idx)
			{
				base.buildExpItemImpl(exp);
			}).code(")");
		}

		// Token: 0x0400003B RID: 59
		private Dictionary<string, string> _operateMapping_1 = new Dictionary<string, string>
		{
			{
				"op_UnaryNegation",
				"-"
			}
		};

		// Token: 0x0400003C RID: 60
		private Dictionary<string, string> _operateMapping_2 = new Dictionary<string, string>
		{
			{
				"op_Addition",
				"+"
			},
			{
				"op_Subtraction",
				"-"
			},
			{
				"op_Multiply",
				"*"
			},
			{
				"op_Division",
				"/"
			},
			{
				"op_Equality",
				"=="
			},
			{
				"op_Inequality",
				"~="
			},
			{
				"op_LessThan",
				"<"
			},
			{
				"op_GreaterThan",
				">"
			},
			{
				"op_GreaterThanOrEqual",
				"<="
			},
			{
				"op_LessThanOrEqual",
				">="
			},
			{
				"op_Modulus",
				"%"
			}
		};
	}
}
